<!DOCTYPE html>
<html lang="en">
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
	<meta charset="utf-8" />
	<title>驴妈妈统计系统</title>
	<meta name="description" content="overview &amp; stats" />
	<meta name="viewport"
		  content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
	<!-- bootstrap & fontawesome -->
	<link rel="stylesheet"
		  href="${rc.contextPath}/assets/css/bootstrap.min.css" />
	<link rel="stylesheet"
		  href="${rc.contextPath}/assets/font-awesome/4.5.0/css/font-awesome.min.css" />
	<!-- page specific plugin styles -->
	<link rel="stylesheet"
		  href="${rc.contextPath}/assets/css/daterangepicker.min.css" />
	<!-- text fonts -->
	<link rel="stylesheet"
		  href="${rc.contextPath}/assets/css/fonts.googleapis.com.css" />
	<!-- ace styles -->
	<link rel="stylesheet"
		  href="${rc.contextPath}/assets/css/ace.min.css"
		  class="ace-main-stylesheet" id="main-ace-style" />
	<link rel="stylesheet"
		  href="${rc.contextPath}/assets/css/ace-skins.min.css" />
	<link rel="stylesheet"
		  href="${rc.contextPath}/assets/css/ace-rtl.min.css" />
	<!-- ace settings handler -->
	<script
			src="${rc.contextPath}/assets/js/jquery-2.1.4.min.js"></script>
	<script src="${rc.contextPath}/assets/js/ace-extra.min.js"></script>

	<script src="${rc.contextPath}/assets/js/user/base.js"></script>
	<link rel="stylesheet"
		  href="${rc.contextPath}/assets/css/bsie-paginator.css" />
</head>

<body class="skin-2" style="background-color: #FFF;">
<div class="tabbable">
	<div class="tab-content">
		<div id="manage" class="tab-pane active in">
			<div class="row">
				<div class="col-xs-12">
					<div class="clearfix">
						<div class="pull-left tableTools-container">
							<button class="btn btn-xs btn-primary" onclick="showMasking()">
								<i class="ace-icon glyphicon glyphicon-plus white"></i>创建指标
							</button>
						</div>
					</div>
					<div id="dynamic-table_wrapper"
						 class="dataTables_wrapper form-inline no-footer">
						<table id="dynamic-table"
							   class="table table-striped table-bordered table-hover dataTable no-footer"
							   role="grid" aria-describedby="dynamic-table_info">
							<thead>
							<tr>
								<th style="display:none">tagId</th>
								<th>No.</th>
								<th>指标名称</th>
								<th>创建者</th>
								<th>最后修改时间</th>
								<th>操作</th>
							</tr>
							</thead>
							<tbody></tbody>
						</table>
						<!-- 分页 -->
						<div class="ui-jqgrid">
							<div id="grid-pager"
								 class="ui-state-default ui-jqgrid-pager ui-corner-bottom"
								 dir="ltr">
								<div id="pg_grid-pager" class="ui-pager-control" role="group">
									<input type="text" id="currentPage" hidden="true" value=1>
									<input type="text" id="page_size" value =10 hidden="true">
									<input type="text" id="page_total" hidden="true">
									<table class="ui-pg-table" style="width: 100%; table-layout: fixed; height: 100%;" cellspacing="0" cellpadding="0" border="0" role="row">
										<tbody>
											<tr>
												<td id="grid-pager_left" align="left"></td>
												<td id="grid-pager_center" align="center" style="white-space: pre; width: 343px;"><table cellspacing="0" cellpadding="0" border="0" style="table-layout: auto;" class="ui-pg-table"><tbody><tr><td id="first_grid-pager" onclick="showPage('firstPage')"
													class="ui-pg-button ui-corner-all" style="cursor: pointer;"><span
															class="ui-icon ace-icon fa fa-angle-double-left bigger-140"></span></td>
													<td id="prev_grid-pager" onclick="showPage('prePage')"
													class="ui-pg-button ui-corner-all" style="cursor: pointer;"><span
															class="ui-icon ace-icon fa fa-angle-left bigger-140"></span></td>
													<td dir="ltr">Page <input class="ui-pg-input" id="page_num"
																			  type="text" size="2" maxlength="7" disabled="true" value="${productRankPage.pageNum}" role="textbox"> of <span
															id="sp_1_grid-pager">${productRankPage.pages}</span></td>
													<td id="next_grid-pager" onclick="showPage('nextPage')"
													class="ui-pg-button ui-corner-all" style="cursor: pointer;"><span
															class="ui-icon ace-icon fa fa-angle-right bigger-140"></span></td>
													<td id="last_grid-pager" onclick="showPage('lastPage')"
													class="ui-pg-button ui-corner-all" style="cursor: pointer;"><span
															class="ui-icon ace-icon fa fa-angle-double-right bigger-140"></span></td>
												</tr></tbody></table></td>
												<td id="grid-pager_right" align="right">
													<div dir="ltr" style="text-align: right" class="ui-paging-info">View
														<span id="view_start_row">${productRankPage.startRow}</span> - <span id="view_end_row">${productRankPage.endRow}</span>
														of <span id="view_page_total">${productRankPage.total}</span>
													</div>
												</td>
											</tr>
										</tbody>
									</table>
								</div>
							</div>
						</div>
						<!-- 分页结束 -->
					</div>
				</div>
			</div>
		</div>
	</div>
</div>


<!-- 弹窗	创建指标 -->
<div class="row">
	<div class="col-xs-12">
		<button class="btn btn-info" data-toggle="modal" type="button" style="display: none;" id="viewpointList" data-target="#myModal"></button>
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog" id="modal-dialog">
				<div class="modal-content">
					<div id="chartMore">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
							<h3 class="modal-title" id="createIndex">创建指标：</h3>
						</div>
						<div class="modal-body">
							<div class="widget-box">
								<div class="widget-header widget-header-small" style="color: #000; font-size: 14px;">
									<div class="ui-jqdialog-content ui-widget-content" id="editcntgrid-table">
										<div>
											<form name="FormPost" id="FrmGrid_grid-table" class="FormGrid" onsubmit="return false;" style="width: auto; height: auto;">
												<div class="FormError ui-state-error" style="display: none;"></div>
												<div class="tinfo topinfo"></div>
												<table id="TblGrid_grid-table"
													   class="EditTable ui-common-table">
													<tbody>
													<tr rowpos="1" class="FormData" id="tr_id">
														<td class="CaptionTD"><label for="id"></label></td>
														<td class="DataTD">&nbsp;<input type="text" id="id" name="id" rowid="_empty" role="textbox" class="FormElement ui-widget-content ui-corner-all"></td>
													</tr>
													<tr rowpos="2" class="FormData" id="tr_sdate">
														<td class="CaptionTD"><label for="sdate">指标名称</label></td>
														<td class="DataTD">&nbsp;<input type="text" oninput="validateSdate()" id="sdate" name="sdate" rowid="_empty" role="textbox" class="FormElement ui-widget-content ui-corner-all">
															<span id = "sdatewarn" hidden="hidden" style="color: #DD1144; font-size: 12px;" >指标名称不能为空</span>
														</td>
													</tr>
													<tr class="FormData" style="display: none">
														<td class="CaptionTD"></td>
														<td colspan="1" class="DataTD">
															<input class="FormElement" id="id_g" type="text" name="grid-table_id" value="_empty">
														</td>
													</tr>
													</tbody>
												</table>
												<div class="binfo topinfo bottominfo"></div>
											</form>
											<table style="height: auto"
												   class="EditTable ui-common-table" id="TblGrid_grid-table_2">
												<tbody>
												<tr>
													<td colspan="2"><hr class="ui-widget-content" style="margin: 1px"></td>
												</tr>
												<tr id="Act_Buttons">
													<td class="EditButton">
														<a id="sData"class="fm-button ui-state-default ui-corner-all fm-button-icon-left btn btn-sm btn-primary">
															<i class="ace-icon fa fa-check"></i>Submit<span class="ui-icon ui-icon-disk" style="display: none;"></span>
														</a>
														<a id="cData" class="fm-button ui-state-default ui-corner-all fm-button-icon-left btn btn-sm">
															<i class="ace-icon fa fa-times"></i>Cancel<span class="ui-icon ui-icon-close" style="display: none;"></span>
														</a>
													</td>
												</tr>
												</tbody>
											</table>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<!--弹窗 创建指标结束 -->
<!--弹窗	修改指标-->
<div class="row">
	<div class="col-xs-12">
		<button class="btn btn-info" data-toggle="modal" type="button" style="display: none;" id="modifypointList" data-target="#myModal2"></button>
		<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog" id="modal-dialog2">
				<div class="modal-content">
					<div id="chartMore2">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
							<h3 class="modal-title" id="modifyIndex">修改指标：</h3>
						</div>
						<div class="modal-body">
							<div class="widget-box">
								<div class="widget-header widget-header-small"
									 style="color: #000; font-size: 14px;">
									<div class="ui-jqdialog-content ui-widget-content" id="editcntgrid-table2">
										<div>
											<form name="FormPost" id="FrmGrid_grid-table2" class="FormGrid" onsubmit="return false;" style="width: auto; height: auto;">
												<input id="modifyId" type="hidden"/>
												<div class="FormError ui-state-error"
													 style="display: none;"></div>
												<div class="tinfo topinfo"></div>
												<table id="TblGrid_grid-table2" class="EditTable ui-common-table">
													<tbody>
													<tr rowpos="1" class="FormData" id="tr_id2">
														<td class="CaptionTD"><label for="id"></label></td>
														<td class="DataTD">&nbsp;<input type="text" id="id2" name="id" rowid="_empty" role="textbox" class="FormElement ui-widget-content ui-corner-all"></td>
													</tr>
													<tr rowpos="2" class="FormData" id="tr_sdate2">
														<td class="CaptionTD"><label for="sdate2">指标名称</label></td>
														<td class="DataTD">&nbsp;<input type="text" oninput="validateSdate2()" id="sdate2" name="sdate2" rowid="_empty" role="textbox" class="FormElement ui-widget-content ui-corner-all">
															<span id = "sdatewarn2" hidden="hidden" style="color: #DD1144; font-size: 12px;" >指标名称不能为空</span>
														</td>
													</tr>
													<tr class="FormData" style="display: none">
														<td class="CaptionTD"></td>
														<td colspan="1" class="DataTD">
															<input class="FormElement" id="id_g2" type="text" name="grid-table_id" value="_empty">
														</td>
													</tr>
													</tbody>
												</table>
												<div class="binfo topinfo bottominfo"></div>
											</form>
											<table style="height: auto" class="EditTable ui-common-table" id="TblGrid_grid-table_22">
												<tbody>
												<tr>
													<td colspan="2"><hr class="ui-widget-content" style="margin: 1px"></td>
												</tr>
												<tr id="Act_Buttons2">
													<td class="EditButton">
														<a id="sModify" class="fm-button ui-state-default ui-corner-all fm-button-icon-left btn btn-sm btn-primary">
															<i class="ace-icon fa fa-check"></i>Submit
															<span class="ui-icon ui-icon-disk" style="display: none;"></span>
														</a>
														<a id="cModify" class="fm-button ui-state-default ui-corner-all fm-button-icon-left btn btn-sm">
															<i class="ace-icon fa fa-times"></i>Cancel
															<span class="ui-icon ui-icon-close" style="display: none;"></span>
														</a>
													</td>
												</tr>
												</tbody>
											</table>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<!-- 弹窗 修改指标结束 -->
<input type="hidden" id="taglistcontext" value="${rc.contextPath}"/>
<script src="${rc.contextPath}/assets/js/bootstrap.min.js"></script>
<script src="${rc.contextPath}/assets/js/jquery-ui.min.js"></script>
<script src="${rc.contextPath}/assets/js/jquery.ui.touch-punch.min.js"></script>
<script src="${rc.contextPath}/assets/js/jquery.gritter.min.js"></script>

<!-- ace scripts -->
<script src="${rc.contextPath}/assets/js/ace-elements.min.js"></script>
<script src="${rc.contextPath}/assets/js/ace.min.js"></script>
<script src="${rc.contextPath}/assets/js/bootbox.js"></script>
<!-- user scripts -->
<script src="${rc.contextPath}/assets/js/user/base.js"></script>

<script type="text/javascript">

	//弹出“新增指标”窗口
	function showMasking(){
		//展示遮罩层
		$("#viewpointList").click();
		//滚动到顶部
		//$('html,body').animate({scrollTop:"0px"},1000);alert($("#axis").val());
	}

	//弹出“修改指标”窗口
	function showModify(tagId, tagName){
		$("#modifyId").val(tagId);
        $("#sdate2").val(tagName);
		$("#modifypointList").click();
	}

    function isNull(str) {
        if(null == str || "" == str || str == "null" || (typeof str == "string" && str.trim() == "")) {
            return true;
        }
        return false;
    }

	var taglistcontext = $("#taglistcontext").val();

	//删除评价指标
	function deleteTag(tagId){
		bootbox.confirm("<strong style='font-size:15px;padding-left:200px'>删除后数据不可恢复，确认删除该指标吗？</strong>", function(result){
			if(result){
				$.ajax({
					url : taglistcontext+'/tags/deleteTag?tagId='+tagId,
					type : "GET",
					async: true,
					success:function(data) {
							window.location.href=taglistcontext+"/tags/list";
					},
					error:function(data) {
					}
				});
			}
		});
	}

    $("#sdate2").bind("keypress",function(event){
        if(event.keyCode == "13") {
			$("#sModify").click();
        }
    });

    $("#sdate").bind("keypress",function(event){
        if(event.keyCode == "13") {
            $("#sData").click();
        }
    });

    function validateSdate2() {
		if(!isNull($("#sdate2").val())) {
            $("#sdatewarn2").hide();
        } else {
            $("#sdatewarn2").show();
        }
    };

    function validateSdate() {
        if(!isNull($("#sdate").val())) {
            $("#sdatewarn").hide();
        } else {
            $("#sdatewarn").show();
        }
    };

	//修改评价指标
	$('#sModify').on('click', function(){
		var tagName = $("#sdate2").val();
		if(!isNull(tagName)){
			$.ajax({
				url : taglistcontext+'/tags/modifyTag?tagName=' + tagName + '&tagId=' + $("#modifyId").val(),
				type : "GET",
				async: true,
				success:function(data) {
						window.location.href=taglistcontext+"/tags/list";
				},
				error:function(data) {
				}
			});
		} else {
            $("#sdatewarn2").show();
		}
	});

	$('#cModify').on('click', function(){
		$('#myModal2').modal('hide');
	});

	$('#cData').on('click', function(){
		$('#myModal').modal('hide');
	});

	//新增评价指标
	$('#sData').on('click', function(){
		var tagName = $("#sdate").val();
		if(!isNull(tagName)){
			$.ajax({
				url : taglistcontext+'/tags/addTag?tagName='+tagName,
				type : "GET",
				async: true,
				success:function(data) {
					window.location.href=taglistcontext+"/tags/list";
				},
				error:function(data) {
				}
			});
		} else {
            $("#sdatewarn").show();
		}
	});

	$(document).ready(function() {
		var currentPage = parseInt($("#currentPage").val());
		var pageSize = $("#page_size").val();
		getTagsList(currentPage, pageSize);
	});

   function getTagsList(currentPage, pageSize) {
        $.ajax({
            url: '${rc.contextPath}/tags/tagsAjaxData',
            type : "GET",
            data: {
            		pageSize:pageSize,
            		pageNum:currentPage
            	 },
            success: function (data) {
            	 var html ="";
            	if(data !="" && data.page.list != "" && data.page.list != null){
			    	var pages = data.page;
                    if (data.page.pages > 1) {
					    $("#page_total").val(pages.pages);
				    	$("#currentPage").val(pages.pageNum);
				    	$("#page_num").val(pages.pageNum);
				    	$("#sp_1_grid-pager")[0].innerText=pages.pages;
				    	$("#view_start_row")[0].innerText= pages.startRow;
				    	$("#view_end_row")[0].innerText= pages.endRow;
				    	$("#view_page_total")[0].innerText= pages.total;

				    	if(pages.isFirstPage) {
				    	    $("#first_grid-pager").addClass("ui-state-disabled");
                            $("#prev_grid-pager").addClass("ui-state-disabled");
						} else {
                            $("#first_grid-pager").removeClass("ui-state-disabled");
                            $("#prev_grid-pager").removeClass("ui-state-disabled");
						}

						if(pages.isLastPage) {
                            $("#next_grid-pager").addClass("ui-state-disabled");
                            $("#last_grid-pager").addClass("ui-state-disabled");
						} else {
                            $("#next_grid-pager").removeClass("ui-state-disabled");
                            $("#last_grid-pager").removeClass("ui-state-disabled");
						}

				    	$(".ui-jqgrid").show();
				    }else{
				  	  $(".ui-jqgrid").hide();
				    }
	                $.each(pages.list, function (index, item) {
	                    html +=
	                     "<tr>"+
							"<td>"+ (index+1) +"</td>"+
							"<td>"+ item.tagName +"</td>"+
							"<td>"+ item.creator +"</td>"+
							"<td>"+ (new Date(item.modifyTime)).Format("yyyy-MM-dd hh:mm:ss") +"</td>"+
							"<td>"+
								"<button class='btn btn-xs btn-info'  onclick=\"showModify("+ item.tagId + ",'" + item.tagName + "')\">"+
									"<i class='ace-icon fa fa-pencil bigger-120'></i>"+
								"</button>"+
								"<button class='btn btn-xs btn-danger' onclick='deleteTag("+item.tagId +")'>"+
									"<i class='ace-icon fa fa-trash-o bigger-120'></i>"+
								"</button>"+
							"</td>"+
						"</tr>";
	                });
	           }else{
			   		html='<tr><td colspan="12"><div class="alert alert-danger" style="margin-bottom: 0px;" role="alert">没有记录!</div></td></tr>';
			   		$(".ui-jqgrid").hide();
			   }
			    $("#dynamic-table tbody").html(html);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.log(XMLHttpRequest.status);
                console.log(XMLHttpRequest.readyState);
                console.log(textStatus);
            }
        });
    }

	//显示页码
    function showPage(param) {
        var endrow = parseInt($("#sp_1_grid-pager")[0].innerText);
        var currentPage = parseInt($("#currentPage").val());
        var page_size = $("#page_size").val();
        if ('firstPage' == param) {
            currentPage = 1;
        }
        else if ('prePage' == param) {
            if (currentPage == 1) {
                currentPage == 1;
            } else {
                currentPage = currentPage - 1;
            }
        }
        else if ('nextPage' == param) {
            if (currentPage == endrow) {
                currentPage = endrow;
            } else {
                currentPage = currentPage + 1;
            }
        } else if ('lastPage' == param) {
            currentPage = endrow;
        }
        getTagsList(currentPage, page_size);
    }

	Date.prototype.Format = function (fmt) { //author: meizz
	    var o = {
	        "M+": this.getMonth() + 1, //月份
	        "d+": this.getDate(), //日
	        "h+": this.getHours(), //小时
	        "m+": this.getMinutes(), //分
	        "s+": this.getSeconds(), //秒
	        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
	        "S": this.getMilliseconds() //毫秒
	    };
	    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	    for (var k in o)
	    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	    return fmt;
	}

	</script>
</body>
</html>